package com.glory.brepda.activity.lanjian.hdg;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.google.android.material.bottomsheet.BottomSheetDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 烘烤/抖动/过回流焊登记 Activity
 */
public class HDGMenuActivity extends BaseActivity {

    @BindView(R.id.llMain)
    LinearLayout llMain;

    @BindView(R.id.btnLotRegister)
    TextView btnFunction1;
    @BindView(R.id.btnMHouseRegister)
    TextView btnFunction2;
    @BindView(R.id.btnSTRegister)
    TextView btnFunction3;
    @BindView(R.id.btnBakeRegister)
    TextView btnFunction4;

    public static final String MR_OPTION = "meta_mHouse_option";
    public static final int MR_OPTION_2ND_FACTORY = 1;
    public static final int MR_OPTION_POST_PROCESS = 2;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_bdh_menu;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
    }

    @Override
    protected void initData() {
    }

    @OnClick(R.id.btnLotRegister)
    public void onBtnLotRegisterClick() {
        Intent intent = new Intent(this, HdgLotRegisterActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btnMHouseRegister)
    public void onBtnMHouseRegisterClick() {
        showMHouseOptionsSheet();
    }

    /**
     * 显示中间仓选项 (二分厂产品接收 / 后工序产品接收)
     */
    private void showMHouseOptionsSheet() {
        BottomSheetDialog dialog = new BottomSheetDialog(this);
        View sheetView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_hdg_mhouse_options, null);
        // 二分厂产品接收
        View option2ndFactory = sheetView.findViewById(R.id.option_2nd_factory);
        // 后工序产品接收
        View optionPostProcess = sheetView.findViewById(R.id.option_post_process);

        option2ndFactory.setOnClickListener(v -> {
            dialog.dismiss();
            Intent intent = new Intent(this, HdgMHouseRegisterActivity.class);
            intent.putExtra(MR_OPTION, MR_OPTION_2ND_FACTORY);
            startActivity(intent);
        });

        optionPostProcess.setOnClickListener(v -> {
            dialog.dismiss();
            Intent intent = new Intent(this, HdgMHouseRegisterActivity.class);
            intent.putExtra(MR_OPTION, MR_OPTION_POST_PROCESS);
            startActivity(intent);
        });

        dialog.setCancelable(true);
        dialog.setContentView(sheetView);
        dialog.show();
    }

    /**
     * 显示烘烤作业选项 （入箱/出箱）
     */
    private void showBakeOptionsSheet() {
        BottomSheetDialog dialog = new BottomSheetDialog(this);
        View sheetView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_hdg_bake_options, null);
        // 烘烤入箱
        View optionBakeIn = sheetView.findViewById(R.id.option_bake_in);
        // 烘烤出箱
        View optionBakeOut = sheetView.findViewById(R.id.option_bake_out);

        optionBakeIn.setOnClickListener(v -> {
            dialog.dismiss();
            Intent intent = new Intent(this, HdgBakeInRegisterActivity.class);
            startActivity(intent);
        });

        optionBakeOut.setOnClickListener(v -> {
            dialog.dismiss();
            Intent intent = new Intent(this, HdgBakeOutRegisterActivity.class);
            startActivity(intent);
        });

        dialog.setCancelable(true);
        dialog.setContentView(sheetView);
        dialog.show();
    }

    @OnClick(R.id.btnSTRegister)
    public void onBtnSTRegisterClick() {
        Intent intent = new Intent(this, HdgSTRegisterActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btnBakeRegister)
    public void onBtnBakeRegisterClick() {
        showBakeOptionsSheet();
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        freeUI_titleView.setTitle("烘烤/抖动/过回流焊登记");
        return new FreeUI_AddViewEntity("header", llMain);
    }
}